import Model from './model'
import proxy from '../proxy.js'
import _ from 'lodash'
import assert from 'assert-plus'

function customProxy (method, conditions, fields, options) {
	return proxy(Model, method, conditions, fields, options)
}

const controller = {
	getAll: async () => {
		return await customProxy('find')
	},
	getTag: async (id) => {
		return await customProxy('findOne', {_id: id, isDelete: false}, '-__v -isDelete')
	},
	getTagsByFatherId: async (id) => {
		return await customProxy('find', {fatherId: id, isDelete: false}, '-__v -isDelete')
	},
	getTagsByFatherName: async (name) => {
		const fatherTag = await customProxy('findOne', {name: name, isDelete: false}, '-__v -isDelete')
		return await customProxy('find', {fatherId: fatherTag._id, isDelete: false}, '-__v -isDelete')
	},
	deleteTag: async (id) => {
		return await customProxy('remove', {_id: id})
	},
	deleteAll: async () => {
		return await customProxy('remove', {})
	},
	createTag: async (info) => {
		return await customProxy('create', info)
	}
}

export default controller